INTEGER FUNCTION soal1a()
	IMPLICIT NONE
	EXTERNAL main1
	
	call main1(1)
	
	soal1a = 1
END

INTEGER FUNCTION soal1b()
	IMPLICIT NONE
	EXTERNAL main1
	
	call main1(2)
	
	soal1b = 1
END

INTEGER FUNCTION soal1c()
	IMPLICIT NONE
	EXTERNAL main1
	
	call main1(3)
	
	soal1c = 1
END

INTEGER FUNCTION soal1d()
	IMPLICIT NONE
	EXTERNAL main2
	
	call main2()
	
	soal1d = 1
END

	
SUBROUTINE main1(choice)
	IMPLICIT NONE
	EXTERNAL bagi,grafik
	WINAPP
	DOUBLE PRECISION epsilon,a,b,hasil,min_v,max_v
	CHARACTER*10 metode(3)
	DATA metode/'bagi dua', 'falsi', 'secant'/
	INTEGER i,k,pil,choice
	COMMON /AREA1/ a,b,k,hasil
	COMMON /AREA2/ pil
	PARAMETER (epsilon = 0.000001)

	pil = choice
	
	k = 1
	a=0.0D0
	b=0.0D0
	hasil = 0.0D0
	
	IF(choice.EQ.1) THEN
		min_v=0.0D0
		max_v=0.9D0
	ELSE
		IF(choice.EQ.2) THEN
			min_v= 0.0D0
			max_v= 100.0D0
		ELSE
			min_v= 0.0D0
			max_v= 100.0D0
		END IF
	END IF

	i	= winio@('%ca[Bagi Dua]%bg[grey]&')
	i	= winio@('Metode =&')
	i  	= winio@('%`ls%ta&',metode,3,k)
	i	= winio@('%2tl&',5,15)
	i	= winio@('%fl&', min_v, max_v) 
	i	= winio@('%itvalue 1%`it=&')
	i	= winio@('%rf&',a)
	i	= winio@('%fl&', min_v, max_v)
	i	= winio@('%ta%itvalue 2%`it=&')
	i	= winio@('%rf&',b)
	i	= winio@('%2nl%cn%40^bt[CARI]&',bagi)
	i	= winio@('%2nl%cn%ob[named_c][Hasil]&')
	i	= winio@('%nl%dy%`rf&',0.0D0,hasil)
	i	= winio@('%nlDitemukan setelah &')
	i	= winio@('%cb%4nl%cn%bt[PRINT]&')
	i	= winio@('%^bt[LIHAT GRAFIK]&',grafik)
	i	= winio@('%bt[BACK]')
END

SUBROUTINE main2() 
	IMPLICIT NONE
	EXTERNAL potong
	INTEGER i, l, r(2)
	CHARACTER*20 metode2(2)
	DOUBLE PRECISION x,y
	DATA metode2/'jacobi', 'newton-rhapton'/r/1,0/
	COMMON /AREA3/ x,y,r,l
	
	x = 0.0D0
	y = 0.0D0
	l = 1
	
	i 	= winio@('%ca[Titik Potong]%bg[grey]&')
	i	= winio@('Metode =&')
	i	= winio@('%`ls%ta&', metode2, 2, l)
	i	= winio@('%2nlTebakan awal=&')
	i	= winio@('%2`ga&',r(1),r(2))
	i	= winio@('%rb[(-1.0, 1.0)]&',r(1))
    i	= winio@('%1ta%rb[(3,0, -3,4)]%2nl&',r(2))
	i	= winio@('%nl%cn%20^bt[CARI]&',potong)
	i	= winio@('%2nl%cn%ob[named_c][Hasil]&')
	i	= winio@('%nl%dyx =%`rf&',0.0D0,x)
	i	= winio@('%nl%dyy =%`rf&',0.0D0,y)
	i	= winio@('%cb%3nl%cn%bt[BACK]')
	
END

INTEGER FUNCTION potong() 
	IMPLICIT NONE
	EXTERNAL form1D_x, form1D_y, form1D_x_proc, form1D_y_proc
	INTEGER r(2),l
	DOUBLE PRECISION x,y, epsilon
	
	PARAMETER (epsilon = 0.000001)
	COMMON /AREA3/ x,y,r,l

	IF(l.EQ.1) THEN
		!jacobi
		IF(r(1).EQ.1) THEN
			x = -1.0
			y = 1.0
			call lelaran_jacobi(form1D_x,form1D_y, epsilon, x, y)
		ELSE
			x = 3.0
			y = -3.4
			call lelaran_jacobi(form1D_x, form1D_y, epsilon,x,y)
		END IF	
	ELSE
		!nrp
		IF(r(1).EQ.1) THEN
			x = -1.0
			y = 1.0
			call nrp(form1D_x_proc, form1D_y_proc, epsilon,x,y)
		ELSE
			x = 3.0
			y = -3.4
			call nrp(form1D_x_proc, form1D_y_proc, epsilon,x,y)
		END IF
	END IF
	
	potong = 1
END	

INTEGER FUNCTION bagi() 
	EXTERNAL form1A, form1B, form1C
	DOUBLE PRECISION a,b,x1,x2,galat,epsilon_mesin,hasil,epsilon,form1A,form1B,form1C
	INTEGER pil
	COMMON /AREA1/ a,b,k,hasil
	COMMON /AREA2/ pil
	
	PARAMETER (galat = 0.000001, epsilon = 0.000001)
	x1 		= a
	x2 		= b
	epsilon_mesin = hitung_epsilon_mesin()	
	
	print*, " "
	
	IF(k.EQ.1) THEN 
		! bagi dua
		IF(pil.EQ.1) THEN
			call bagi_dua_galat(form1A,epsilon_mesin, galat,  x1, x2 , hasil)
		ELSE
			IF(pil.EQ.2) THEN
				call bagi_dua_galat(form1B,epsilon_mesin, galat,  x1, x2 , hasil)
			ELSE
				call bagi_dua_galat(form1C,epsilon_mesin, galat,  x1, x2 , hasil)
			END IF
		END IF
	ELSE
		IF(k.EQ.2) THEN
			! falsi
			IF(pil.EQ.1) THEN
				call regula_falsi_galat(form1A,epsilon_mesin,delta,galat,x1,x2,hasil)
			ELSE
				IF(pil.EQ.2) THEN
					call regula_falsi_galat(form1B,epsilon_mesin,delta,galat,x1,x2,hasil)
				ELSE
					call regula_falsi_galat(form1C,epsilon_mesin,delta,galat,x1,x2,hasil)
				END IF
			END IF
		ELSE
			! secant
			IF(pil.EQ.1) THEN
				call secant_galat(form1A,epsilon_mesin,galat,x1,x2,hasil)
			ELSE
				IF(pil.EQ.2) THEN
					call secant_galat(form1B,epsilon_mesin,galat,x1,x2,hasil)
				ELSE
					call secant_galat(form1C,epsilon_mesin,galat,x1,x2,hasil)
				END IF
			END IF
		END IF
	END IF
	
	bagi = 1
END

INTEGER FUNCTION grafik()

	COMMON /AREA2/ pil
	INTEGER i, N, j, pil
	PARAMETER (N=999)
	DOUBLE PRECISION y(N), x, inc
	
	IF(pil.EQ.1) THEN
		inc = 0.01D0
		x = 0.001
		DO i=1,N
			y(i)= form1A(x)
			x	= x + 0.001
		END DO
	ELSE
		inc = 0.12D0
		x = 0.01
		IF(pil.EQ.2) THEN
			DO i=1,N
				y(i)= form1B(x)
				x	= x + 0.01
			END DO
		ELSE
			DO i=1,N
				y(i)= form1C(x)
				x	= x + 0.01
			END DO
		END IF
	END IF
	
	j	= winio@('%ca[Grafik]%bg[grey]&')		
	j	= winio@('%pl[x_axis=x, y_axis=y, y_max=10, title="Grafik fungsi",colour=red,y_min=-10]&',400,600,N,0.0D0,inc,y)
	j	= winio@('%ff%nl%cn%bt[OK]')
	
	grafik = 1

END